package com.axioma.dbmaint.datalayer.dto;

import com.axioma.dbmaint.datalayer.dto.util.DBVendor;
import com.axioma.dbmaint.datalayer.dto.util.Status;


// Really, we need ServerDTO interface, and then implement PGServerDTO that can return a postgres URL,
// and a SSServerDTO that can build a Sql Server URL.  For now, though...we'll hack around on this.
public class ServerDTO implements Cloneable {
   private final String serverName;
   private final String masterDatabaseName;
   private final Integer port;
   private final DBVendor vendor;
   private Status status;
   private final String user;
   private final String password;
      
   public ServerDTO(String serverName, Integer port, DBVendor vendor, String masterDBName,
         Status status, String user, String password) {
      super();
      this.masterDatabaseName = masterDBName;
      this.serverName = serverName;
      this.port = port;
      this.vendor = vendor;
      this.status = status;
      this.user = user;
      this.password = password;
   }

   @Override
   public Object clone() throws CloneNotSupportedException {
      return super.clone();
   }

   public String getUser() {
      return user;
   }

   public String getPassword() {
      return password;
   }

   public String getServerName() {
      return serverName;
   }

   public Integer getPort() {
      return port;
   }

   public String getMasterDatabaseName() {
      return this.masterDatabaseName;
   }
   
   public DBVendor getVendor() {
      return vendor;
   }

   public Status getStatus() {
      return status;
   }

   public void setStatus(Status status) {
      this.status = status;
   }

   @Override
   /* Status is left out of this, since it is not a persistent value */
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime
            * result
            + ((masterDatabaseName == null) ? 0 : masterDatabaseName.hashCode());
      result = prime * result + ((password == null) ? 0 : password.hashCode());
      result = prime * result + ((port == null) ? 0 : port.hashCode());
      result = prime * result
            + ((serverName == null) ? 0 : serverName.hashCode());
      result = prime * result + ((user == null) ? 0 : user.hashCode());
      result = prime * result + ((vendor == null) ? 0 : vendor.hashCode());
      return result;
   }

   @Override
   /* Status is left out of this, since it is not a persistent value */
   public boolean equals(Object obj) {
      if (this == obj)
         return true;
      if (obj == null)
         return false;
      if (getClass() != obj.getClass())
         return false;
      ServerDTO other = (ServerDTO) obj;
      if (masterDatabaseName == null) {
         if (other.masterDatabaseName != null)
            return false;
      } else if (!masterDatabaseName.equals(other.masterDatabaseName))
         return false;
      if (password == null) {
         if (other.password != null)
            return false;
      } else if (!password.equals(other.password))
         return false;
      if (port == null) {
         if (other.port != null)
            return false;
      } else if (!port.equals(other.port))
         return false;
      if (serverName == null) {
         if (other.serverName != null)
            return false;
      } else if (!serverName.equals(other.serverName))
         return false;
      if (user == null) {
         if (other.user != null)
            return false;
      } else if (!user.equals(other.user))
         return false;
      if (vendor != other.vendor)
         return false;
      return true;
   }



   
}